#include<iostream>
#include<algorithm>
using namespace std;
int x[10];
int main()
{
	int n;
	while(cin>>n && n)
	{
		for(int i=1;i<=n;i++)
			x[i]=i;
		do
		{
			for(int i=1;i<=n;i++)
				cout<<x[i]<<" ";
			cout<<endl;
		}while(next_permutation(x+1,x+n+1));
	}
    return 0;
}
